home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4214 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: inforamp.net!ts44-07
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How can I have 2 instances of a program write appending to a file?
  5. Date: Fri, 02 Feb 96 18:13:16 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4etjtu$7s1@sam.inforamp.net>
  8. References: <9601311707.AA04679@cae1-5.agt.gmeds.com>
  9. NNTP-Posting-Host: ts44-07.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <9601311707.AA04679@cae1-5.agt.gmeds.com>,
  13.    "David S. Pesetsky 230-6088 AGT/8880" <iedsp@agt.gmeds.com> wrote:
  14. >Platform: IBM RISC6000 AIX3.2.5 X11R5
  15. >
  16. >I need to make a c-program that can append strings to one file without
  17. >interfering with other instances of that program which are running. In other
  18. >words, I need it to check if the file is open, if it is, wait until it's 
  19. available, then
  20. >write to it. I don't want to mess with process id's. Can I do it?
  21. >
  22. >Please e-mail your response to me 'cause I can't receive USENET. Thanks.
  23. >
  24. >Dave
  25.  
  26. I'll just paste in an example that I use.
  27. Some of the code might not be compatible with your platform.
  28.  
  29. ----------------------------------------------------------------------
  30. time_t StartTime=time(NULL);
  31.  
  32. while ((hFile=sopen(cszFilename, O_RDWR | O_BINARY, SH_DENYRW)) == -1)
  33. {
  34.     if (dwStatus) *dwStatus = FALSE;
  35.     if (StartTime+60>time(NULL)) break;
  36.     /* When this function returns dwStatus=FALSE
  37.         an error should be reported
  38.         and execution should be terminated */
  39. }
  40.  
  41. if (hFile!=-1)
  42.     if (dwStatus) *dwStatus = TRUE;
  43. ----------------------------------------------------------------------
  44.  
  45. Using sopen is the key to the whole thing.
  46. I think sopen is in most of the standard libraries.
  47.  
  48. Agrivar
  49.